from django.contrib.auth.models import AbstractUser
from django.db import models


class User(AbstractUser):
    class Meta:
        db_table = 'auth_user'
        verbose_name = '用户管理'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username


# 小车表
class CarsObject(models.Model):
    id = models.CharField(primary_key=True,max_length=255,verbose_name="设备编号（mac）")
    status = models.BooleanField(default=False,verbose_name="当前状态")  # 可使用 不可使用
    power = models.CharField(max_length=10,default='100',verbose_name="剩余电量")
    num = models.IntegerField(default=0,verbose_name="巡检次数")
    user = models.OneToOneField(blank=True,null=True,to=User,on_delete=models.CASCADE,verbose_name="操作员")
    def getid(self):
        return self.id

    def __str__(self):
        return self.id

    class Meta:
        verbose_name = '设备管理'
        verbose_name_plural = verbose_name



    # user_type = models.IntegerField(choices=((1,"超级用户"),(2,"普通用户")))
# 版本控制
class VersionControl(models.Model):
    version = models.FloatField(max_length=10,verbose_name="版本号")
    detail = models.CharField(max_length=255,verbose_name="更新内容")
    upLoad_time = models.DateTimeField(auto_now_add=True,verbose_name="更新时间")
    download_num = models.IntegerField(null=True,default=0,verbose_name="下载量")
    app = models.FileField(upload_to="apps/")

    class Meta:
        verbose_name = 'app软件版本'
        verbose_name_plural = verbose_name

    def __str__(self):
        return str(self.version)


"""巡检日志"""
class Logs(models.Model):
    date = models.DateTimeField(auto_now_add=True,verbose_name="巡检时间")
    detail = models.CharField(max_length=255,verbose_name="巡检内容")
    isFinished = models.BooleanField(default=False,verbose_name="处理状态")
    car = models.ForeignKey(to=CarsObject,on_delete=models.CASCADE,verbose_name="巡检小车")
    equName = models.CharField(max_length=20,verbose_name="巡检设备")
    state = models.BooleanField(default=False,verbose_name="是否异常")
    user = models.ForeignKey(to=User,on_delete=models.CASCADE,verbose_name="操作人员")

    class Meta:
        verbose_name = '巡检日志'
        verbose_name_plural = verbose_name
